package com.sjh;

import java.time.LocalDateTime;
import java.util.Timer;
import java.util.TimerTask;

/**
 * @author jack
 * @data 2020/8/21 10:47 上午
 */
public class TraditionalThread {

    public static void main(String[] args) throws InterruptedException {
        // 写一个定时器实现每隔2秒，4秒触发
        new Timer().schedule(new TimerTaskTest(), 2000);
        while (true){
            System.out.println(LocalDateTime.now().getSecond());
            Thread.sleep(1000);
        }

    }

static class TimerTaskTest extends TimerTask {
    static int count =0;
    @Override
    public void run() {
        count = (count+1) % 2;
        System.out.println("bombing");
        new Timer().schedule(new TimerTaskTest(),2000+ (2000 * count));
    }
}
}
